package AccionBoton;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import java.util.ResourceBundle;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

import modelUtil.Util;
import paginas.PaginaFuncionBoton;

public class AccionComponerAccion implements ActionListener{
	
	private PaginaFuncionBoton _frame;
	
	
	public AccionComponerAccion(PaginaFuncionBoton frame){
		
		_frame = frame;
		
	}
	
	@SuppressWarnings("unused")
	public void actionPerformed(ActionEvent e){
		
		JTree tree = _frame.getTree();
		DefaultMutableTreeNode nodo = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
		DefaultMutableTreeNode padre = (DefaultMutableTreeNode) nodo.getParent();
		Enumeration <String> conjunto = ResourceBundle.getBundle("internacionalizacion/Acciones").getKeys();
		Enumeration <String> conjunto2 = ResourceBundle.getBundle("internacionalizacion/Acciones").getKeys();
		String AccionConcreta = (String)nodo.getUserObject();
		String acciones = _frame.getAccionCompuesta().getText();
		if(!acciones.equals("")){
			String clave = Util.BuscarClave((String)nodo.getUserObject(), ResourceBundle.getBundle("internacionalizacion/Acciones").getKeys());
			if(clave==""){
				acciones = acciones + "+" + "{" + AccionConcreta + "}";
			}else{
				
				acciones = acciones + "+" + clave;

			}
			
			
		}else{
			
			String clave = Util.BuscarClave((String)nodo.getUserObject(), ResourceBundle.getBundle("internacionalizacion/Acciones").getKeys());
			if(clave==""){
			acciones = "{"+(String)nodo.getUserObject()+"}";
			}else{
				acciones = clave;
			}
			
		}
		
		_frame.getAccionCompuesta().setText(acciones);
		_frame.pack();
		_frame.repaint();
		
	}

}
